function ICal(input) {
	var obj;
	//determine input
	try{
		//is json
		obj = JSON.parse(input);
	}catch(err){
		//is ics
		obj = ical2json(input);
	}
	this.obj = obj;

	function ical2json(ical){
			var lines=ics.split('\n');
			var output ={};
			var current = output;
			var parent=[];
			for(var i in lines){
				var line=lines[i];
				var entry = line.split(':');
				if(entry[0]=='BEGIN'){
					if(current[entry[1]]){
						//already exists
						current[entry[1]].push({});
						parent.push(current);
						current=current[entry[1]][current[entry[1]].length-1];
					} else {
						current[entry[1]] = [{}];
						parent.push(current);
						current=current[entry[1]][0];
					}
					
				} else if(entry[0]=='END'){
					current=parent.pop();
				} else
					current[entry[0]]=entry[1];
			}
			return output;
		};

	function parseLevel(obj){
		var out ="";
		for(var i in obj){
			if(i=='' || i.trim()==''){
				//found mepty line
				continue;
			}
			if(obj[i].push){
				//iterate over elements
				for(var f in obj[i]){
					if(typeof obj[i][f] == 'object'){
				//found BEGIN
				out+="BEGIN:"+i+"\n";
				out+=parseLevel(obj[i][f]);
				out+="END:"+i+"\n";
			}else
				out+=f+":"+obj[i][f]+"\n";
				}
			} else 		if(typeof obj[i] == 'object'){
				//found BEGIN
				out+="BEGIN:"+i+"\n";
				out+=parseLevel(obj[i]);
				out+="END:"+i+"\n";
			}else
				out+=i+":"+obj[i]+"\n";
		}
		return out;
	}
	ICal.prototype.toJSON = function(){
		return JSON.stringify(this.obj);
	}
	ICal.prototype.toJSONpretty = function(){
		return JSON.stringify(this.obj,null,4);
	}
	ICal.prototype.toICal = function(){
		return parseLevel(this.obj);
	}
	ICal.prototype.getSummary = function(){
		return this.obj.VCALENDAR[0].VEVENT[0].SUMMARY;
	}
	ICal.prototype.isRepeating = function(){
		if(this.obj.VCALENDAR[0].VEVENT[0].REPEAT){
			return true;
		}else{
			return false;
		}
	}
}